package com.infocollect.project.grant.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.infocollect.framework.aspectj.lang.annotation.Log;
import com.infocollect.framework.aspectj.lang.enums.BusinessType;
import com.infocollect.project.grant.domain.GrGranttype;
import com.infocollect.project.grant.service.IGrGranttypeService;
import com.infocollect.framework.web.controller.BaseController;
import com.infocollect.framework.web.domain.AjaxResult;
import com.infocollect.common.utils.poi.ExcelUtil;
import com.infocollect.framework.web.page.TableDataInfo;

/**
 * 项目类型Controller
 * 
 * @author infocollect
 * @date 2022-05-14
 */
@RestController
@RequestMapping("/grant/granttype")
public class GrGranttypeController extends BaseController
{
    @Autowired
    private IGrGranttypeService grGranttypeService;

    /**
     * 查询项目类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GrGranttype grGranttype)
    {
        startPage();
        List<GrGranttype> list = grGranttypeService.selectGrGranttypeList(grGranttype);
        return getDataTable(list);
    }

    /**
     * 导出项目类型列表
     */
    @PreAuthorize("@ss.hasPermi('grant:granttype:export')")
    @Log(title = "项目类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GrGranttype grGranttype)
    {
        List<GrGranttype> list = grGranttypeService.selectGrGranttypeList(grGranttype);
        ExcelUtil<GrGranttype> util = new ExcelUtil<GrGranttype>(GrGranttype.class);
        return util.exportExcel(list, "granttype");
    }

    /**
     * 获取项目类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('grant:granttype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(grGranttypeService.selectGrGranttypeById(id));
    }

    /**
     * 新增项目类型
     */
    @PreAuthorize("@ss.hasPermi('grant:granttype:add')")
    @Log(title = "项目类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrGranttype grGranttype)
    {
        return toAjax(grGranttypeService.insertGrGranttype(grGranttype));
    }

    /**
     * 修改项目类型
     */
    @PreAuthorize("@ss.hasPermi('grant:granttype:edit')")
    @Log(title = "项目类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrGranttype grGranttype)
    {
        return toAjax(grGranttypeService.updateGrGranttype(grGranttype));
    }

    /**
     * 删除项目类型
     */
    @PreAuthorize("@ss.hasPermi('grant:granttype:remove')")
    @Log(title = "项目类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(grGranttypeService.deleteGrGranttypeByIds(ids));
    }
}
